<?php
	class Db{
		protected $host = 'localhost';
		protected $user = 'root';
		protected $senha = 'root';
		protected $bd = 'php_agenda';
		
		public function getHost(){
			return $this->host;
		}
		public function getUser(){
			return $this->user;
		}
		public function getSenha(){
			return $this->senha;
		}
		
		public function connect(){
			mysql_connect($this->host, $this->user, $this->senha);
			mysql_select_db($this->bd);
		}
		
		public function select($colunas, $tabela, $where=""){
			$sql = "select $colunas from $tabela $where";
			$result = mysql_query($sql);
			$ret = array();
			if(mysql_num_rows($result)>0){
				for($i=0;$i<mysql_num_rows($result);$i++){
					$ret[] = mysql_fetch_array($result);
				}
			}
			return $ret;
		}
		
		public function delete($tabela, $id){
			$sql = "delete from $tabela where id=$id";
			mysql_query($sql);
		}
		
		public function insert($tabela, $campos, $valores){
			$sql = "insert into $tabela ($campos) values ($valores)";
			mysql_query($sql);
		}
		public function findById($id, $tabela){
			$sql = "select * from $tabela where id = $id";
			$res = mysql_query($sql);
			$ret = mysql_fetch_array($res);
			return $ret;
		}
		public function update($tabela, $valores, $id){
			$sql = "update $tabela set $valores where id=$id";
			mysql_query($sql);
		}
		
	}
?>
